//
//  LittleBallConfigViewController.m
//  LittleBall
//
//  Created by mac on 11-12-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "LittleBallConfigViewController.h"

   
@implementation LittleBallConfigViewController

@synthesize creator;
@synthesize m_gameManagement;
@synthesize m_feedback;
@synthesize difficultySelection;
@synthesize m_confirm;
@synthesize m_cancel;
@synthesize m_info;
@synthesize m_infoView;
@synthesize m_musicSlider;
@synthesize m_soundSlider;
@synthesize m_lable_difficulty;
@synthesize m_lable_music;
@synthesize m_lable_sound;

- (id)init
{
    self = [super init];
    if (self) {
    }
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    m_musicSlider.value = [m_gameManagement getMusicVolume];
    m_soundSlider.value = [m_gameManagement getSoundVolume];

    switch ([m_gameManagement getGameDifficluty])
    {
        case 0:
            [difficultySelection setSelectedSegmentIndex:0];
            break;
        case 1:
            [difficultySelection setSelectedSegmentIndex:1];
            break;
        case 2:
            [difficultySelection setSelectedSegmentIndex:2];
            break;
        default:
            break;
    }
}
   
- (IBAction)onButton_Cancel:(id)sender
{
    //[creator setConfigurationPause:NO];
    [self.view removeFromSuperview];
    [creator hiddenButtons:false];
}

- (IBAction)onButton_Confirm:(id)sender
{
    //[creator setConfigurationPause:NO];  

    [m_gameManagement setVolumeOfMusic:m_musicSlider.value Sound:m_soundSlider.value];    
    [m_gameManagement WriteDataIntoFile];

    [creator removeConfigViewAnimation];
}

- (IBAction)onButton_info:(id)sender
{
    [self.view addSubview:m_infoView];

    m_gameManagement.m_viewChangeAnimationDelegate = [m_gameManagement.m_viewChangeAnimationDelegate initWithFrom:self To:m_infoView ChangeType:LB_VIEW_CHANGE_CONFIG_TO_INFO];
}

- (IBAction)updateMusicVolume:(UISlider *)slider
{
    float tempMusicVolume = [slider value];
    [m_gameManagement setVolumeOfMusic:tempMusicVolume Sound:m_soundSlider.value];
}

- (IBAction)updateSoundVolume:(UISlider *)slider
{
    float tempSoundVolume = [slider value];
    [m_gameManagement setVolumeOfMusic:m_soundSlider.value Sound:tempSoundVolume];
}

- (IBAction)sendFeedBack:(id)sender
{
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
	if (mailClass != nil)
	{
		if ([mailClass canSendMail])
		{
			[self displayComposerSheet];
		}
        
	}
}

- (void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    
	picker.mailComposeDelegate = self;
	
	[picker setSubject:@"消小球反馈"];
	
	NSArray *toRecipients = [NSArray arrayWithObject:@"***@boolooleeloo.com"]; 
	
	[picker setToRecipients:toRecipients];
	
	[self presentModalViewController:picker animated:YES];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{	
	[self dismissModalViewControllerAnimated:YES];
}

- (void)chooseDifficulty:(id)sender
{
    if (difficultySelection.selectedSegmentIndex == 0)
    {
        //tempGameDifficulty = EASY;
        [m_gameManagement setGameDifficulty:EASY];
    }        
    if (difficultySelection.selectedSegmentIndex == 1)
    {
        //tempGameDifficulty = MEDIUM;
        [m_gameManagement setGameDifficulty:MEDIUM];
    }        
    if (difficultySelection.selectedSegmentIndex == 2)
    {
        //tempGameDifficulty = HARD;
        [m_gameManagement setGameDifficulty:HARD];
    }        
}

- (IBAction)configGoBack:(id)sender
{
    // do nothing...
}

- (IBAction)infoGoBack:(id)sender
{    
    m_gameManagement.m_viewChangeAnimationDelegate = [m_gameManagement.m_viewChangeAnimationDelegate initWithFrom:m_infoView To:self ChangeType:LB_VIEW_CHANGE_INFO_TO_CONFIG];
    
}

- (IBAction)onButton_GameCenter:(id)sender
{
    gameCenter = [[LittleBallGameCenterViewController alloc] initWithNibName:@"LittleBallGameCenterView" bundle:nil];
    gameCenter.view.center = CGPointMake(384.0f, 300.0f);
    
    //m_gameManagement.m_viewChangeAnimationDelegate = [m_gameManagement.m_viewChangeAnimationDelegate initWithFrom:gameCenter.view To:self ChangeType:LB_VIEW_CHANGE_INFO_TO_CONFIG];
    [self.view addSubview:gameCenter.view];
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

- (void)didReceiveMemoryWarning
{
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    switch (interfaceOrientation) 
    {
    case UIInterfaceOrientationPortrait:
    case UIInterfaceOrientationPortraitUpsideDown:
        return true;

    default:
        break;
    }
    
    return false;
}

@end
